/****************************************************
          File Name:list.h
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Wed 15 Oct 2014 05:52:42 PM CST
*****************************************************/

#if !defined LIST_H_
#define LIST_H_ 1

#include "59-4.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

/* make a new type */
typedef struct Node {
    struct Node *link;
    int number;
	char name[40];
} Node;

/* create a list from a file */
Node *lopen(char *filename);

/* create new list */
Node *lcreate(int num, int sfd);
/* modify list */
/* find 'where' and replace its value with 'new_value' */
int modify(Node *head, int where, char *new_value);

/* determine if an elemnet in list */
/* return 0 : not in list ; return 1: in list */
int isInlist(Node *head, int number);

/* add a new elemnet to list */
/* 'where' determine insert at the head of list or other place */
int insert(Node **linkd, int where, char *name);

/* delete an elemnet from list */
int ldelete(Node **linked, int where);

/* display all elemnets of list */
int show(Node *head, int fd, SA *client);

/* calculate the length of a list */
int len(Node *head);

/* rank from large to small or small to large */
Node *lrank(Node *head, char *option);

/* find number and then return a node of list */
Node *lfind(Node *head, int number);

/* save list to a file */
int save(Node *head, const char filename[]);

/* release resource */
int destroy(Node *head);

#endif
